package com.example.spring.controller;

import com.example.spring.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.annotation.RequestScope;

import javax.annotation.Resource;

/**
 * ClassName: BeanController
 * Package: IntelliJ IDEA
 * Description:
 *
 * @Author 谷京京
 * @Create 2024/4/11 11:43
 * @Version 1.0
 */
@RequestMapping("/scope")
@RestController
public class BeanController {
    @Autowired
    private ApplicationContext context;

    @Resource(name = "requestUser")
    private User requestUser;

    @RequestMapping("/request")
    public String request() {
        User user = (User) context.getBean("requestUser");
        return "context: " + System.identityHashCode(user) + "属性注入: " + System.identityHashCode(requestUser);
    }
}
